﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

using LTorrent.Extensions;

namespace LTorrent.Peers
{
    class PieceMessage:IPeerMessages
    {

        public byte[] Message
        {
            get { throw new NotImplementedException(); }
        }

        protected MemoryStream _message;


        public PieceMessage(Byte[] Information, UInt32 Index, UInt32 Begin)
        {
            _message = new MemoryStream();

            Byte[] Temp = ((UInt32)(Information.Length + 9)).toNetworkOrder();
            _message.Write(Temp, 0, Temp.Length);

            _message.WriteByte(7);//ID

            Temp = Index.toNetworkOrder();
            _message.Write(Temp, 0, Temp.Length);

            Temp = Begin.toNetworkOrder();
            _message.Write(Temp, 0, Temp.Length);

            _message.Write(Information, 0, Information.Length);

        }

        ~PieceMessage()
        {
            _message.Close();
        }
    }
}
